/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author DUCLOI
 */
public class BTHSo1_2 extends MIDlet implements CommandListener{

    private Form fmForm1;
    private Form fmForm2;
    private Ticker tk;
    private TextField tfText;
    private Command cmOK;
    private Command cmChange;
    private Command cmExit;
    
    public BTHSo1_2()
    {
        fmForm1 = new Form("Bài thực hành 1");
        tk = new Ticker("Hello");
        cmChange = new Command("Change", Command.SCREEN, 0);
        cmExit = new Command("Exit", Command.EXIT, 1);
        fmForm1.addCommand(cmChange);
        fmForm1.addCommand(cmExit);
        fmForm1.setTicker(tk);
        fmForm1.setCommandListener(this);
        
        fmForm2 = new Form ("Thay đổi Ticker");
        tfText = new TextField("Text", "", 50, 0);
        cmOK = new Command("OK", Command.OK, 1);
        fmForm2.append(tfText);
        fmForm2.addCommand(cmOK);
        fmForm2.setCommandListener(this);
    }
    public void startApp() {
        Display.getDisplay(this).setCurrent(fmForm1);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    public void commandAction(Command c, Displayable d)
    {
        if (c == cmExit)
        {
            destroyApp(false);
            notifyDestroyed();
        }
        else if (c == cmChange)
        {
            Display.getDisplay(this).setCurrent(fmForm2);
        }
        else if (c == cmOK)
        {
            tk.setString(tfText.getString());
            Display.getDisplay(this).setCurrent(fmForm1);
        }
    }
}